# coding:utf-8
from rest_framework import serializers
from goods_info.models import UnitsModel


class UnitsSerializer(serializers.ModelSerializer):
    """
    计量单位的序列化器和反序列化
    """
    #增加一个新属性：把基本单位和副单位结合在一起
    units_name=serializers.SerializerMethodField(read_only=True)
    class Meta:
        model = UnitsModel
        fields = "__all__"

    def get_units_name(self,obj):
        return str(obj)#调用该对象的__str__函数